package com.ruoyi.web.controller.memberManagement;


import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MemberLevelOperationLog;
import com.ruoyi.system.service.IMemberLevelOperationLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员等级折扣操作记录（存储会员等级的创建、删除、默认设置及修改等操作记录）Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="会员等级折扣操作记录")
@RestController
@RequestMapping("/system/memberLevelOperationLog")
public class MemberLevelOperationLogController extends BaseController
{
    @Autowired
    private IMemberLevelOperationLogService memberLevelOperationLogService;

    /**
     * 查询会员等级折扣操作记录列表
     */
    @ApiOperation("查询会员等级折扣操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String operationType, @RequestParam(required = false) Long levelId, @RequestParam(required = false) Date operationStartAt, @RequestParam(required = false) Date operationEndAt)
    {
        startPage();
        List<MemberLevelOperationLog> list = memberLevelOperationLogService.selectMemberLevelOperationLogList(operationType,levelId,operationStartAt,operationEndAt);
        return getDataTable(list);
    }

    /**
     * 导出会员等级折扣操作记录列表
     */
    @ApiOperation("导出会员等级折扣操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "会员等级折扣操作记录（存储会员等级的创建、删除、默认设置及修改等操作记录）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String operationType,@RequestParam(required = false) Long levelId,@RequestParam(required = false) Date operationStartAt,@RequestParam(required = false) Date operationEndAt)
    {
        List<MemberLevelOperationLog> list = memberLevelOperationLogService.selectMemberLevelOperationLogList(operationType,levelId,operationStartAt,operationEndAt);
        ExcelUtil<MemberLevelOperationLog> util = new ExcelUtil<MemberLevelOperationLog>(MemberLevelOperationLog.class);
        util.exportExcel(response, list, "会员等级折扣操作记录（存储会员等级的创建、删除、默认设置及修改等操作记录）数据");
    }

    /**
     * 获取会员等级折扣操作记录列表
     */
    @ApiOperation("获取会员等级折扣操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberLevelOperationLogService.selectMemberLevelOperationLogById(id));
    }

    /**
     * 新增会员等级折扣操作记录列表
     */
    @ApiOperation("新增会员等级折扣操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "会员等级折扣操作记录（存储会员等级的创建、删除、默认设置及修改等操作记录）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberLevelOperationLog memberLevelOperationLog)
    {
        return toAjax(memberLevelOperationLogService.insertMemberLevelOperationLog(memberLevelOperationLog));
    }

    /**
     * 修改会员等级折扣操作记录列表
     */
    @ApiOperation("修改会员等级折扣操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "会员等级折扣操作记录（存储会员等级的创建、删除、默认设置及修改等操作记录）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberLevelOperationLog memberLevelOperationLog)
    {
        return toAjax(memberLevelOperationLogService.updateMemberLevelOperationLog(memberLevelOperationLog));
    }

    /**
     * 删除会员等级折扣操作记录列表
     */
    @ApiOperation("删除会员等级折扣操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "会员等级折扣操作记录（存储会员等级的创建、删除、默认设置及修改等操作记录）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberLevelOperationLogService.deleteMemberLevelOperationLogByIds(ids));
    }
}
